// pages/mine/mine.js
const app = getApp()
Page({

    /**
     * 
     * 页面的初始数据
     */
    data: {
        userInfo: {},
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo'),
        orderStatistics:{
            state1: { label: '待付款', status: 0, icon: 'icon-money_icon' },
            state2: { label: '待收货', status: 2, icon: 'icon-dingwei' },
            state3: { label: '已完成', status: 3, icon: 'icon-ico_orderAdd' },
            state4: { label: '已取消', status: -1, icon: 'icon-nodata' },
            state5: { label: '全部订单', status: '', icon: 'icon-order' },
        },
    },
    moreOrder(e) {
        var status = e.currentTarget.dataset.status;
        wx.navigateTo({
            url: '../order/order?status=' + status
        });
    },
    goDetail(){
        console.log(this.data.userInfo);
        wx.navigateTo({
            url: './detail/detail'
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        if (app.globalData.userInfo) {
            this.setData({
                userInfo: app.globalData.userInfo,
                hasUserInfo: true
            })
        } else if (this.data.canIUse) {
            // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
            // 所以此处加入 callback 以防止这种情况
            app.userInfoReadyCallback = res => {
                this.setData({
                    userInfo: res.userInfo,
                    hasUserInfo: true
                })
            }
        } else {
            // 在没有 open-type=getUserInfo 版本的兼容处理
            wx.getUserInfo({
                success: res => {
                    app.globalData.userInfo = res.userInfo
                    this.setData({
                        userInfo: res.userInfo,
                        hasUserInfo: true
                    })
                }
            })
        }

        console.log('data', this.data);
        console.log('app', app);
    },
    getUserInfo: function(e) {
        console.log(e)
        app.globalData.userInfo = e.detail.userInfo
        console.log('app', app);
        this.setData({
            userInfo: e.detail.userInfo,
            hasUserInfo: true
        })
    }
})